/**
 * Copyright (c) 2008 Andrew Rapp. All rights reserved.
 *  
 * This file is part of XBee-API.
 *  
 * XBee-API is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *  
 * XBee-API is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with XBee-API.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.rapplogic.xbee.api.zigbee;

import java.util.HashMap;
import java.util.Map;

import com.rapplogic.xbee.api.XBeeAddress16;
import com.rapplogic.xbee.api.XBeeFrameIdResponse;

public class ZNetTxStatusResponse extends XBeeFrameIdResponse {

    public /*enum*/ static class DeliveryStatus {

        public static final DeliveryStatus SUCCESS = new DeliveryStatus(0);
        public static final DeliveryStatus CCA_FAILURE = new DeliveryStatus(0x02);
        public static final DeliveryStatus INVALID_DESTINATION_ENDPOINT = new DeliveryStatus(0x15);
        public static final DeliveryStatus NETWORK_ACK_FAILURE = new DeliveryStatus(0x21);
        public static final DeliveryStatus NOT_JOINED_TO_NETWORK = new DeliveryStatus(0x22);
        public static final DeliveryStatus SELF_ADDRESSED = new DeliveryStatus(0x23);
        public static final DeliveryStatus ADDRESS_NOT_FOUND = new DeliveryStatus(0x24);
        public static final DeliveryStatus ROUTE_NOT_FOUND = new DeliveryStatus(0x25);
        public static final DeliveryStatus PAYLOAD_TOO_LARGE = new DeliveryStatus(0x74);
        private static final Map lookup = new HashMap();


        static {
            lookup.put(SUCCESS.getValue(), SUCCESS);
            lookup.put(CCA_FAILURE.getValue(), CCA_FAILURE);
            lookup.put(INVALID_DESTINATION_ENDPOINT.getValue(), INVALID_DESTINATION_ENDPOINT);
            lookup.put(NETWORK_ACK_FAILURE.getValue(), NETWORK_ACK_FAILURE);
            lookup.put(NOT_JOINED_TO_NETWORK.getValue(), NOT_JOINED_TO_NETWORK);
            lookup.put(SELF_ADDRESSED.getValue(), SELF_ADDRESSED);
            lookup.put(ADDRESS_NOT_FOUND.getValue(), ADDRESS_NOT_FOUND);
            lookup.put(ROUTE_NOT_FOUND.getValue(), ROUTE_NOT_FOUND);
            lookup.put(PAYLOAD_TOO_LARGE.getValue(), PAYLOAD_TOO_LARGE);
        }
        private final int value;

        DeliveryStatus(int value) {
            this.value = value;
        }

        public static DeliveryStatus get(int value) {
            return (DeliveryStatus) lookup.get(new Integer(value));
        }

        public Integer getValue() {
            return new Integer(value);
        }
    }

    public /*enum*/ static class DiscoveryStatus {

        public static final DiscoveryStatus NO_DISCOVERY = new DiscoveryStatus(0);
        public static final DiscoveryStatus ADDRESS_DISCOVERY = new DiscoveryStatus(1);
        public static final DiscoveryStatus ROUTE_DISCOVERY = new DiscoveryStatus(2);
        public static final DiscoveryStatus ADDRESS_AND_ROUTE_DISCOVERY = new DiscoveryStatus(3);
        private static final Map lookup = new HashMap();


        static {
            lookup.put(NO_DISCOVERY.getValue(), NO_DISCOVERY);
            lookup.put(ADDRESS_DISCOVERY.getValue(), ADDRESS_DISCOVERY);
            lookup.put(ROUTE_DISCOVERY.getValue(), ROUTE_DISCOVERY);
            lookup.put(ADDRESS_AND_ROUTE_DISCOVERY.getValue(), ADDRESS_AND_ROUTE_DISCOVERY);

        }
        private final int value;

        DiscoveryStatus(int value) {
            this.value = value;
        }

        public static DiscoveryStatus get(int value) {
            return (DiscoveryStatus) lookup.get(new Integer(value));
        }

        public Integer getValue() {
            return new Integer(value);
        }
    }
    private XBeeAddress16 remoteAddress16;
    private int retryCount;
    private DeliveryStatus deliveryStatus;
    private DiscoveryStatus discoveryStatus;

    public ZNetTxStatusResponse() {
    }

    public XBeeAddress16 getRemoteAddress16() {
        return remoteAddress16;
    }

    public void setRemoteAddress16(XBeeAddress16 remoteAddress) {
        this.remoteAddress16 = remoteAddress;
    }

    public int getRetryCount() {
        return retryCount;
    }

    public void setRetryCount(int retryCount) {
        this.retryCount = retryCount;
    }

    public DeliveryStatus getDeliveryStatus() {
        return deliveryStatus;
    }

    public void setDeliveryStatus(DeliveryStatus deliveryStatus) {
        this.deliveryStatus = deliveryStatus;
    }

    public DiscoveryStatus getDiscoveryStatus() {
        return discoveryStatus;
    }

    public void setDiscoveryStatus(DiscoveryStatus discoveryStatus) {
        this.discoveryStatus = discoveryStatus;
    }

    /**
     * Returns true if the delivery status is SUCCESS
     *
     * @return
     */
    public boolean isSuccess() {
        return this.getDeliveryStatus() == DeliveryStatus.SUCCESS;
    }

    public String toString() {
        return super.toString() +
                ",remoteAddress16=" + this.remoteAddress16 +
                ",retryCount=" + this.retryCount +
                ",deliveryStatus=" + this.deliveryStatus +
                ",discoveryStatus=" + this.discoveryStatus;
    }
}